   var initData = function(num){
	    var param = {
			page_num:num,
			page_size:"10",
			project_id:project_id
	    }
		$.ajax({
	        url: base + "/projectCenter/businessdata/initEquipmentEquipListByProjectId",
	        data: param,
	        success: function (data, textStatus, jqXHR) {
	        	if(data != null){
		        	var pageCount = data.pager.pageCount;
		        	var dataObj ={
		        			"list":data.list,
		         			"dataTool":{
		         				"title":{
		          			      	"equipment_equip_code": "设备配备库代号"
		          			      	,"equipment_equip_name": "设备配备库名称"
		          			      	,"create_time":"创建时间"
		          			      	,"update_time":"修改时间"
		          			      	,"operation":"操作"
		            			},
		            			"titleCheckbox":false,
								"btn":[{"event":"updateObj","name":"编辑"},
								       {"event":"equipmentSelection","name":"查看设备"},
								       {"event":"delObj","name":"删除"}]
							}
			  		};
		        	showPageTable('view', dataObj,num,pageCount,"initData");
	        	}
	        },
	        error: function () {
	        }
	    });
}
   //设备选型
   var equipmentSelection = function(obj){
	    var equipment_equip_id = obj.id;
	    var tab_type = $(".layui-this").attr("data_id");
	    var url = base+"/projectCenter/businessdata/equipmentSelection/"+equipment_equip_id+"/"+tab_type;
	    $.get(url, function(result){
	  	   $(".layui-show").html("");
	 	   $(".layui-show").html(result);
	    });
   }
   
   
   
   var searchData = function(){
	   var num = 1;
	   searchInfo(num);
   }
   
   //搜索
   var searchInfo = function(num){
	   var searchName = $.trim($("#searchName").val());
	    var param = {
				page_num:num,
				page_size:"10",
				project_id:project_id,
				searchName:searchName
		    }
		$.ajax({
	        url: base + "/projectCenter/businessdata/initEquipmentEquipListByProjectId",
	        data: param,
	        success: function (data, textStatus, jqXHR) {
	        	if(data != null){
		        	var pageCount = data.pager.pageCount;
		        	var dataObj ={
		        			"list":data.list,
		         			"dataTool":{
		         				"title":{
		          			      	"equipment_equip_code": "设备配备库代号"
		          			      	,"equipment_equip_name": "设备配备库名称"
		          			      	,"create_time":"创建时间"
		          			      	,"update_time":"修改时间"
		          			      	,"operation":"操作"
		            			},
		            			"titleCheckbox":false,
								"btn":[{"event":"updateObj","name":"编辑"},
								       {"event":"equipmentSelection","name":"查看设备"},
								       {"event":"delObj","name":"删除"}]
							}
			  		};
		        	showPageTable('view', dataObj,num,pageCount,"searchInfo");
	        	}
	        },
	        error: function () {
	        }
	    });
	    
   }
   
   //新增设备配备信息
   var addData = function(){
		var contentDiv = function(){
			var content;
			var data={
					"title":{
						    "id":"id",
						    "project_id":"项目id",
						    "equipment_equip_code":"设备配备编号",
					      	"equipment_equip_name": "设备配备名称",
					},"text":{
						    "id":""
						    ,"project_id":project_id
						    ,"equipment_equip_code":""
						    ,"equipment_equip_name":""
					},"input":{
						    "id":"hidden"
						    ,"project_id":"hidden"
						    ,"equipment_equip_code":"text"
						    ,"equipment_equip_name":"text"
					},"input_init":{
					}
			};
			var getDiv =  dc_update.innerHTML;
			laytpl(getDiv).render(data, function(html){
				content = html;
			}); 
			return content;
		}
		layopen(contentDiv());
   }
   
   //编辑设备配备信息
   var updateObj = function(obj){
		var contentDiv = function(){
			var content;
			var data={
					"title":{
						    "id":"id",
						    "equipment_equip_code":"设备配备编号",
					      	"equipment_equip_name": "设备配备名称",
					},"text":{
						    "id":obj.id
						    ,"equipment_equip_code":obj.equipment_equip_code
						    ,"equipment_equip_name":obj.equipment_equip_name
					},"input":{
						    "id":"hidden"
						    ,"equipment_equip_code":"text_readonly"
						    ,"equipment_equip_name":"text"
					},"input_init":{
					}
			};
			var getDiv =  dc_update.innerHTML;
			laytpl(getDiv).render(data, function(html){
				content = html;
			}); 
			return content;
		}
		layopen(contentDiv());
   }
   
   //渲染弹窗
   var layopen = function(content){
		layer.open({
		  	title:'更新设备配备信息'
			,content: content
	    	,area: ['650px', '650px']
		    ,scrollbar: false
		  	,btn: ['确认', '取消']
			,yes: function(index,layero){ //确认
				var data = $(layero).find("form").serializeJSON();
				if(data.equipment_equip_name == ""){
					var obj = $("input[name='equipment_equip_name']");
					obj.focus();
					layer.tips('请填写设备配备信息!', obj);
					return false;
				}
				if(data.equipment_equip_code == ""){
					var obj = $("input[name='equipment_equip_code']");
					obj.focus();
					layer.tips('请填写设备配备代号!', obj);
					return false;
				}
				commitData(data);
			}
	});  
   }
   
   var delObj = function(obj){
	   layer.confirm('确认删除?',{btn : [ '确定', '取消' ]},function(index){
		   layer.close(index);
		   var param = {id:obj.id}
		   $.ajax({
			   url:base+"/projectCenter/businessdata/delEquipmentEquipById",
			   data:param,
			   success:function(data,status){
				    if(data.statusCode == 0){
						layer.msg(data.message, {
							icon : 1
						});
				    }else{
						layer.msg(data.message, {
							icon : 5
						});
				    }
				    initData(1);
			   }
		   });
	   });
   }
   
   $("#initEquipmentEquip").click(function(){
	   var load_index = layer.load(1, {shade: [0.1,'#fff'],scrollbar: false});
	   //var load_index = layer.msg('加载中', {icon: 16,shade: 0.01,scrollbar: false});
	   $.get(base+"/projectCenter/businessdata/initEquipmentInfo/"+project_id, function(result){
		   layer.close(load_index);
		   layer.msg('初始化设备配备库成功!', {icon: 1,time:1000});
		   initData(1);
	   });
   });
   
   
   //更新数据
   var commitData = function(data){
		$.post(base+"/projectCenter/businessdata/updateEquipmentEquip",data,function (data,status){
			if(data!=""&&data!=null){
				if(data.statusCode == 0){
					layer.msg('更新成功', {icon: 1,time:1000});
				}else{
					layer.msg(data.message, {icon: 2,time:1000});
				}
			}else{
				layer.msg('更新失败!', {icon: 2,time:1000});
			}
			initData(1);
  		 })
   }
   
   $(document).ready(function(){
	   initData(1);
	   $("#addData").click(addData);
	   $("#searchInfo").click(searchData);
   });
   